package com.kayden.aop.proxy;

import net.sf.cglib.proxy.Enhancer;

import java.lang.reflect.Proxy;

public class Main {

    public static void main(String[] args) {
        HouseSubject target = new RealHouseSubject();
//        HouseSubject houseSubject  = new HouseProxy(target);
//        houseSubject.saleHouse();
//        houseSubject.rentHouse();

        //JDK动态管理
        //动态创建一共代理类
//        HouseSubject houseProxy = (HouseSubject) Proxy.newProxyInstance(target.getClass().getClassLoader(), new Class[]{HouseSubject.class},new JDKInvocation(target));
//        houseProxy.rentHouse();
//        houseProxy.saleHouse();


        //Cglib动态管理
        //--add-opens java.base/java.lang=ALL-UNNAMED
        HouseSubject houseProxy = (HouseSubject) Enhancer.create(target.getClass(),new CGlibMethodInterceptor(target));
        houseProxy.saleHouse();
        houseProxy.rentHouse();
    }

}
